﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;

namespace POSSystem.BLL
{
    public class InvoiceDetails :_InvoiceDetails
    {
        public InvoiceDetails()
        {
        }

        public void AddInfo(int invoiceID, int productID, string IMEI, int qty, decimal gst, decimal unitPrice, decimal discount, decimal cost, string desc)
        {
            this.InvoiceID = invoiceID;
            this.ProductID = productID;
            this.IMEI = IMEI;
            this.Quantity = qty;
            this.GST = gst;
            this.UnitPrice = unitPrice;
            this.Deleted = false;
            this.LastModifiedDate = DateTime.UtcNow.AddHours(SystemVariables.SysVars.TimeZone);
            this.Discount = discount;
            this.Description = desc;
            this.Cost = cost;
            this.BranchID = Branches.CurrentBranchID;
        }

        public void AddInfo(int invoiceID, string IMEI, int qty, decimal gst, decimal unitPrice, decimal discount, decimal cost, string desc)
        {
            this.InvoiceID = invoiceID;
            this.IMEI = IMEI;
            this.Quantity = qty;
            this.GST = gst;
            this.UnitPrice = unitPrice;
            this.Deleted = false;
            this.LastModifiedDate = DateTime.UtcNow.AddHours(SystemVariables.SysVars.TimeZone);
            this.Discount = discount;
            this.Description = desc;
            this.Cost = cost;
            this.BranchID = Branches.CurrentBranchID;
        }

        const String strProductName = "ProductName";
        const String strTotal = "Total";

        public void AddInfoPlus(int invoiceID, int productID, string IMEI, String productName, int qty, decimal gst, decimal unitPrice, decimal cost,  string desc)
        {
            this.InvoiceID = invoiceID;
            this.ProductID = productID;
            this.IMEI = IMEI;
            this.Quantity = qty;
            this.GST = gst;
            this.UnitPrice = unitPrice;
            this.Deleted = false;
            this.LastModifiedDate = DateTime.UtcNow.AddHours(SystemVariables.SysVars.TimeZone);
            if (this.DataTable.Columns[strProductName] == null)
                this.AddColumn(strProductName, typeof(String));
            if (this.DataTable.Columns[strTotal] == null)
                this.AddColumn(strTotal, typeof(Decimal));
            this.SetColumn(strProductName, productName);
            this.Discount = 0;
            this.SetColumn(strTotal, qty * unitPrice);
            this.Cost = cost;
            this.Description = desc;
            this.BranchID = Branches.CurrentBranchID;
        }

        public void AddInfoPlus(int invoiceID, string IMEI, String productName, int qty, decimal gst, decimal unitPrice, decimal cost, string desc)
        {
            this.InvoiceID = invoiceID;
            this.IMEI = IMEI;
            this.Quantity = qty;
            this.GST = gst;
            this.UnitPrice = unitPrice;
            this.Deleted = false;
            this.LastModifiedDate = DateTime.UtcNow.AddHours(SystemVariables.SysVars.TimeZone);
            if (this.DataTable.Columns[strProductName] == null)
                this.AddColumn(strProductName, typeof(String));
            if (this.DataTable.Columns[strTotal] == null)
                this.AddColumn(strTotal, typeof(Decimal));
            this.SetColumn(strProductName, productName);
            this.Discount = 0;
            this.SetColumn(strTotal, qty * unitPrice);
            this.Cost = cost;
            this.Description = desc;
            this.BranchID = Branches.CurrentBranchID;
        }

        public Decimal Total
        {
            get
            {
                return (Decimal)this.GetColumn(strTotal);
            }
            set
            {
                this.SetColumn(strTotal, value);
            }
        }

        public String ProductName
        {
            get
            {
                return (String)this.GetColumn(strProductName);
            }
            set
            {
                this.SetColumn(strProductName, value);
            }
        }

        public static InvoiceDetails GetInvoiceDetails(int invoiceID)
        {
            InvoiceDetails details = new InvoiceDetails();
            details.Where.InvoiceID.Value = invoiceID;
            details.Where.Deleted.Value = false;
            details.Query.Load();

            return details;
        }
    }
}
